<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<link rel="stylesheet" type="text/css" href="../../css/btnplus.css" />
		<style type="text/css">
			html,body{
				background-color: #F7F8FA;
			}
			.add_input{ margin-top: 10px; background-color: #fff; line-height:48px; padding: 0 15px;}
			.add_input li{ position:relative;}
			.add_input li:not(:last-child)::after{ position: absolute; content: ""; left: 0; bottom: 0; right: -10px; border-top: 1px #d5d5d5 solid; transform: scaleY(0.5);}
			.add_input b{ display:block; font-size: 15px; font-weight: 400; color: #333;}
			.add_input input{ display:block; border: 0; width: 100%; box-sizing: border-box; text-align: right; font-size: 14px; color: #333; padding: 12px 0;}
			.add_input input.on{ padding-right: 15px; background: url(../../image/img_13.png) no-repeat right center; background-size: 6px auto;}
			
			.upload_img input{ position:absolute; right: 0; top: 0; bottom: 0; width: 100%; opacity: 0; z-index: 2;}
			
			.upload{ margin-top: 10px; padding: 0 15px 10px; background-color: #fff;}
			.upload li{ float:left; width: 70px; position: relative; margin-right: 4%; margin-bottom: 2%;}
			.upload li:nth-child(4n+4){ margin-right: 0;}
			.upload a{ display:block; position: relative; overflow: hidden;}
			.upload img{ width: 70px; height:70px; border-radius: 3px; object-fit: cover;}
			.upload input{ position:absolute; right: 0; top: 0; bottom: 0; opacity: 0;}
			.upload em{ position:absolute; right: -8px; top: -8px; width: 17px; height: 17px; border-radius: 50%; background: url(../../image/img_33.png); background-size: 100% auto;}
			.add_btn{ padding: 45px 15px;}
			
			.upload_img{ margin-top: 10px; padding: 0 15px; background-color: #fff; overflow: hidden;}
			.upload_img b{ display:block; position: relative; margin-bottom: 2px; font-size: 15px; color: #333; font-weight: 400; line-height: 50px; }
			.upload_img b div{ position: absolute; right: 0; top: 0; font-size: 13px; color: #333; line-height: 50px; height: 50px;}
			.upload_img b div span,.add_input .m_cell_ft span{ float:left; margin-left: 20px; padding-left: 18px; background: url(../../image/img_24.png) no-repeat 0 18px; line-height: 50px; background-size: 13px auto;}
			.upload_img b div span.on,.add_input .m_cell_ft span.on{ background-image: url(../../image/img_25.png);}
			.upload_img ul{ padding-bottom: 10px;}
			.upload_img li{ float:left; width: 48.5%; height:106px; border: 0.5px #9F9F9F solid; border-radius: 6px; margin-bottom:10px; overflow: hidden; position: relative;}
			.upload_img li:nth-child(2n){ float: right;}
			.upload_img2 .img{ width: 100%; border-radius: 4px;}
			.upload_img .img{ display:none; width: 100%; height:200px; object-fit: cover;}
			.upload_img li.on{ border:0;}
			.upload_img li.on i{ display:block;}
			.upload_img li.on div{ display:none;}
			.upload_img li.on .img{ display:block;}
			.upload_img i{ display:none; position:absolute; right: 10px; top: 10px; width: 20px; height: 20px; border-radius: 50%; background-image: url(../../image/img_33.png); background-size: 100% auto; z-index: 3;}
			
			.upload_img li div{ position:absolute; left: 0; top: 50%; right: 0; transform: translateY(-50%); text-align: center; font-size: 12px; color: #999;}
			.upload_img li div img{ margin:0 auto; width: 25px; }
			.upload_img li p{ padding-top: 5px;}
			.btn { padding:15px; }
			/*上传资料*/
			.add_input .m_cell_ft span{ float:right; font-size: 13px; line-height: 42px; background-position: 0 14px;}
			.grlb{ padding: 10px 15px 0;}
			.grlb p{ color: #333; line-height: 30px; height: 30px; position: relative; padding-left: 18px; font-size: 12px;}
			.grlb a{ display:inline; color: #1c63fa;}
			.grlb em{ position: absolute; left: 0; top: 8px; width: 13px; height: 13px; border-radius: 50%; background-image: url(../../image/img_24.png); background-size: 100% auto;}
			.grlb em.on{ background-image: url(../../image/img_25.png);}
			.d_btn span { opacity:0.49; }
			.color-333 { color: #333 !important; } 
			.display-none{ display:none; }
		</style>
	</head>
	<body>
		<div class="add_input">
			<ul>
				<li>
					<div class="m_cell_hd"><b id="shouyiname">投保单位</b></div>
					<div class="m_cell_ft m_cell_primary"><input type="text" id="beneficiary" class="limitinput" limit-num="50" value="" placeholder="企业名称" /></div>
				</li>
				<li id="realnamediv">
					<div class="m_cell_hd"><b>企业法人</b></div>
					<div class="m_cell_ft m_cell_primary"><input type="text" id="realname" class="limitinput" limit-num="10" value="" placeholder="法人姓名" /></div>
				</li>
				<li>
					<div class="m_cell_hd"><b id="zhengjianname">统一社会信用代码</b></div>
					<div class="m_cell_ft m_cell_primary"><input type="text" id="idcard" value="" placeholder="统一社会信用代码号码" /></div>
				</li>
				<li>
					<div class="m_cell_hd"><b>车牌号</b></div>
					<div class="m_cell_ft m_cell_primary" tapmode onclick="selCarnum();"><input type="text" id="carnum" value="" placeholder="例：浙A·12321" readonly /></div>
				</li>
				<li>
					<div class="m_cell_hd"><b>投保类型</b></div>
					<div class="m_cell_ft m_cell_primary" id="cartypelist">
						<span tapmode data-cartype="2" onclick="selCartype(this);">续保</span>
						<span tapmode data-cartype="1" onclick="selCartype(this);" class="on">新车投保</span>
					</div>
				</li>
			</ul>
		</div>

		
		<div class="upload_img" id="companypicdiv">
			<b>统一社会信用代码照片(营业执照)</b>
			<ul class="clearfix">
				<li tapmode onclick="selpic(3);">
					<i tapmode onclick="delimg(this,3);"></i>
					<div>
						<img src="../../image/img_32.png" alt="" />
					</div>
					<img src="../../image/kong.png" id="cardIDthumb3" class="img"/>
					<input type="hidden" name="cardIDthumb_3" id="cardIDthumb_3" value="" />
				</li>
			</ul>
		</div>
		<div class="upload_img" id="hegepicdiv">
			<b>车辆合格证照片</b>
			<ul class="clearfix">
				<li tapmode onclick="selpic(11);">
					<i tapmode onclick="delimg(this,11);"></i>
					<div>
						<img src="../../image/img_32.png" alt="" />
					</div>
					<img src="../../image/kong.png" id="cardIDthumb11" class="img"/>
					<input type="hidden" name="cardIDthumb_11" id="cardIDthumb_11" value="" />
				</li>
			</ul>
		</div>
		<div class="upload_img display-none">
			<b>车辆强制保险保单照片</b>
			<ul class="clearfix">
				<li tapmode onclick="selpic(4);">
					<i tapmode onclick="delimg(this,4);"></i>
					<div>
						<img src="../../image/img_32.png" alt="" />
					</div>
					<img src="../../image/kong.png" id="cardIDthumb4" class="img"/>
					<input type="hidden" name="cardIDthumb_4" id="cardIDthumb_4" value="" />
				</li>
			</ul>
		</div>

		<div class="upload_img display-none">
			<b>车辆商业保险保单照片
			<div id="havepictypelist">
				<span tapmode onclick="selPictype(this,1);" class="on">有</span>
				<span tapmode onclick="selPictype(this,0);">无</span>
			</div>
			</b>
			<ul class="clearfix" id="picarea">
				<li tapmode onclick="selpic(5);">
					<i tapmode onclick="delimg(this,5);"></i>
					<div>
						<img src="../../image/img_32.png" alt="" />
					</div>
					<img src="../../image/kong.png" id="cardIDthumb5" class="img"/>
					<input type="hidden" name="cardIDthumb_5" id="cardIDthumb_5" value="" />
				</li>
			</ul>
		</div>

		<div class="upload_img display-none" id="xingshizhengdiv">
			<b>车辆行驶证照片（正副本）</b>
			<ul class="clearfix">
				<li tapmode onclick="selpic(6);">
					<i tapmode onclick="delimg(this,6);"></i>
					<div>
						<img src="../../image/img_32.png" alt="" />
						<p>正本照片</p>
					</div>
					<img src="../../image/kong.png" id="cardIDthumb6" class="img"/>
					<input type="hidden" name="cardIDthumb_6" id="cardIDthumb_6" value="" />
				</li>
				<li tapmode onclick="selpic(7);">
					<i tapmode onclick="delimg(this,7);"></i>
					<div>
						<img src="../../image/img_32.png" alt="" />
						<p>副本照片</p>
					</div>
					<img src="../../image/kong.png" id="cardIDthumb7" class="img"/>
					<input type="hidden" name="cardIDthumb_7" id="cardIDthumb_7" value="" />
				</li>
			</ul>
		</div>
		
		<div class="upload_img display-none">
			<b>车辆照片</b>
			<ul class="clearfix">
				<li tapmode onclick="selpic(8);">
					<i tapmode onclick="delimg(this,8);"></i>
					<div>
						<img src="../../image/img_32.png" alt="" />
						<p>车辆左45度照</p>
					</div>
					<img src="../../image/kong.png" id="cardIDthumb8" class="img"/>
					<input type="hidden" name="cardIDthumb_8" id="cardIDthumb_8" value="" />
				</li>
				<li tapmode onclick="selpic(9);">
					<i tapmode onclick="delimg(this,9);"></i>
					<div>
						<img src="../../image/img_32.png" alt="" />
						<p>车辆右45度照</p>
					</div>
					<img src="../../image/kong.png" id="cardIDthumb9" class="img"/>
					<input type="hidden" name="cardIDthumb_9" id="cardIDthumb_9" value="" />
				</li>
				<li tapmode onclick="selpic(10);">
					<i tapmode onclick="delimg(this,10);"></i>
					<div>
						<img src="../../image/img_32.png" alt="" />
						<p>车辆后方照</p>
					</div>
					<img src="../../image/kong.png" id="cardIDthumb10" class="img"/>
					<input type="hidden" name="cardIDthumb_10" id="cardIDthumb_10" value="" />
				</li>
			</ul>
		</div>

		<div class="grlb">
			<p><span tapmode onclick="agreenterm(this);"><em class="" id="btnagreen"></em>我已阅读并同意</span><a href="javascript:;" tapmode onclick="openNavWin('#ddd','insureterms_win','insureterms_frm.html','车辆联保协议',false,false,true,[],{});">《车辆联保协议》</a></p>
		</div>
		<!--上传资料end-->

		<div class="f_line"></div>
		<div class="btn">
			<button class="d_btn" tapmode="btnpress" onclick="addinsure();" id="login-btn"><span>下一步</span></button>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/app.js"></script>
	<script type="text/javascript" src="../../script/permission.js"></script>
	<script type="text/javascript" src="../../script/doT.js"></script>
	<script type="text/javascript">
		var usertype;
		var cartype = 1;
		var pictype = 1;
		var maxlen = 10;
		var licencePlatekeyboard;
		var curImgId = 0;
		apiready = function() {
			api.parseTapmode();
			usertype = api.pageParam.usertype;
			
			if(usertype == 2) {
				maxlen = 50;

			}
			
			
			licencePlatekeyboard = api.require('licencePlatekeyboard');
			   
			//getJsonFromAPI();
			api.addEventListener({
                name: 'navitembtn'
            }, function(ret, err) {
                if (ret.type == 'left') {
					api.closeWin({
					});
                }
            });
			
			var flag = false
			var inputs = $api.domAll('.limitinput');
			for (var i = 0; i < inputs.length; i++) {
				inputs[i].oninput = function() {
					var limitnum = $api.attr(this,'limit-num');
					setTimeout(() => {
						if (!flag){
							var len = this.value.length;
							if(this.value.length > limitnum)
							{
								this.value = this.value.substr(0,limitnum);
								len = 50;
							}
						}
					}, 0);
				}
			}
			document.addEventListener('compositionstart', function(e) {
				flag = true;
			});
			document.addEventListener('compositionend', function(e) {
				flag = false;
			});
		}
		function checknamelen(obj) {
			
			inputlimit(obj,maxlen);
		}
		function addinsure() {
			document.activeElement.blur();
			var beneficiary = $api.val($api.byId('beneficiary')).trim();
			var realname = $api.val($api.byId('realname')).trim();
			var cardID = $api.val($api.byId('idcard')).trim();
			var carnum = $api.val($api.byId('carnum')).trim();
			var cardIDthumb1 = '';//$api.val($api.byId('cardIDthumb_1')).trim();
			var cardIDthumb2 = '';//$api.val($api.byId('cardIDthumb_2')).trim();
			var cardIDthumb3 = $api.val($api.byId('cardIDthumb_3')).trim();
			var cardIDthumb4 = $api.val($api.byId('cardIDthumb_4')).trim();
			var cardIDthumb5 = $api.val($api.byId('cardIDthumb_5')).trim();
			var cardIDthumb6 = $api.val($api.byId('cardIDthumb_6')).trim();
			var cardIDthumb7 = $api.val($api.byId('cardIDthumb_7')).trim();
			var cardIDthumb8 = $api.val($api.byId('cardIDthumb_8')).trim();
			var cardIDthumb9 = $api.val($api.byId('cardIDthumb_9')).trim();
			var cardIDthumb10 = $api.val($api.byId('cardIDthumb_10')).trim();
			var cardIDthumb11 = $api.val($api.byId('cardIDthumb_11')).trim();
			
			var tsname = '受益人姓名';
			var tsn = '受益人';
			if(usertype == 2)
			{
				tsname = '企业名称';
				tsn = '法人';
			}
			
			if($api.cssVal($api.byId('login-btn'),'opacity')!=1)
			{
				return false;
			}
			if(beneficiary == '')
			{
				showtoast("warning","请填写"+tsname);
				return false;
			}
			if(usertype == 2 && realname == '')
			{
				showtoast("warning","请填写"+tsn+"姓名");
				return false;
			}
			if(cardID == '')
			{
				showtoast("warning","请填写统一社会信用代码");
				return false;
			}
			
			if(carnum == '')
			{
				showtoast("warning","请填写车牌号");
				return false;
			}
			if(cardIDthumb3=="")
			{
				showtoast("warning","请上传统一社会信用代码照片");
				return false;
			}
			if(cartype == 1 && cardIDthumb11=="")
			{
				showtoast("warning","请上传车辆合格证照片");
				return false;
			}
			if(cardIDthumb4=="")
			{
				//showtoast("warning","请上传强制保单图片");
				//return false;
			}
			if(pictype == 1)
			{
				if(cardIDthumb5=="")
				{
					//showtoast("warning","请上传商业保单图片");
					//return false;
				}
			}
			if(cartype == 2 && cardIDthumb6=="")
			{
				showtoast("warning","请上传行驶证正本");
				return false;
			}
			if(cartype == 2 && cardIDthumb7=="")
			{
				showtoast("warning","请上传行驶证副本");
				return false;
			}
			if(cardIDthumb8=="")
			{
				//showtoast("warning","请上传车辆左45°照");
				//return false;
			}
			if(cardIDthumb9=="")
			{
				//showtoast("warning","请上传车辆右45°照");
				//return false;
			}
			if(cardIDthumb10=="")
			{
				//showtoast("warning","请上传车辆后方照");
				//return false;
			}
			if(!$api.hasCls($api.byId('btnagreen'),'on'))
			{
				showtoast("warning","同意联保协议才可以下一步");
				return false;
			}
			showbtnloading('login-btn');
			
			var paramsObj = {
				beneficiary: beneficiary,
				realname: realname,
				cardID: cardID,
				carnum: carnum,
				cartype: cartype,
				usertype: usertype,
				cardIDthumb1: cardIDthumb1,
				cardIDthumb2: cardIDthumb2,
				cardIDthumb3: cardIDthumb3,
				cardIDthumb4: cardIDthumb4,
				cardIDthumb5: cardIDthumb5,
				cardIDthumb6: cardIDthumb6,
				cardIDthumb7: cardIDthumb7,
				cardIDthumb8: cardIDthumb8,
				cardIDthumb9: cardIDthumb9,
				cardIDthumb10: cardIDthumb10,
				cardIDthumb11: cardIDthumb11,
				step: 1
			}
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret && ret.value)
				{
					var userinfo = JSON.parse(ret.value);
					api.ajax({
						url: ApiUrl + '/v1/insure',
						method: 'post',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						},
						data: {
							values: paramsObj
						}
					}, function(ret, err) {
						if (ret) {
							var insureid = ret.insureid;
							opWin('selectinsure_win','selectinsure_win.html',false,{insureid:insureid},false);
						} else {
							console.log(JSON.stringify(err));
							showtoast("warning",err.body.error);
						}
						hidebtnloading('login-btn','下一步');
					});
				}
			});
		}
		function isLicenseNo(str) {
			//检验车牌号
			return /(^[\u4E00-\u9FA5]{1}[A-Z0-9]{6}$)|(^[A-Z]{2}[A-Z0-9]{2}[A-Z0-9\u4E00-\u9FA5]{1}[A-Z0-9]{4}$)|(^[\u4E00-\u9FA5]{1}[A-Z0-9]{5}[挂学警军港澳]{1}$)|(^[A-Z]{2}[0-9]{5}$)|(^(08|38){1}[A-Z0-9]{4}[A-Z0-9挂学警军港澳]{1}$)/.test(str);
		}
		function agreenterm(obj) {
			$api.toggleCls(obj.firstElementChild,'on');
		}
		function funcChina(str){ 
			if(/.*[\u4e00-\u9fa5]+.*$/.test(str)) 
			{ 
				//alert("不能含有汉字！"); 
				return false; 
			} 
			return true; 
		}
		function inputcarnum(str) {
			var carnum = $api.val($api.byId('carnum'));
			
			//carnum += '' + str;
			
			if(!funcChina(str))
			{
				carnum = str;
			}
			else
			{
				if(carnum.length < 7) {
					carnum += '' + str;
				}
			}
			$api.val($api.byId('carnum'),carnum);
			if(carnum.length == 7)
			{
				api.execScript({
					frameName: 'setcarnum_frm',
					script: 'closeframe();'
				});
				checkCarnum();
			}
		}
		function backspacecarnum() {
			var carnum = $api.val($api.byId('carnum'));
			carnum = carnum.substring(0,carnum.length-1);
			$api.val($api.byId('carnum'),carnum);
		}
		function selCarnum() {
			document.activeElement.blur();
			setTimeout(function(){
				api.openFrame({
					name: 'setcarnum_frm',
					url: 'setcarnum_frm.html',
					bounces: false,
					rect: {
						x: 0,
						y: 0,
						w: 'auto',
						h: 'auto'
					},
					bgColor: 'rgba(0,0,0,0.3)',
					pageParam: {
						fromwin: 'addinsurecompany'
					}
				});	
			}, 0);
		}
		function selCarnumold() {
			document.activeElement.blur();
			//选择车牌号
			licencePlatekeyboard.open(function(ret) {
				if(ret.clickListener != '删除')
				{
					var carnum = $api.val($api.byId('carnum'));
					carnum += '' + ret.clickListener;
					
					if(!funcChina(ret.clickListener))
					{
						carnum = ret.clickListener;
					}
					$api.val($api.byId('carnum'),carnum);
					if(carnum.length == 7)
					{
						licencePlatekeyboard.close();
						checkCarnum();
					}
				}
				else
				{
					var carnum = $api.val($api.byId('carnum'));
					carnum = carnum.substring(0,carnum.length-1);
					$api.val($api.byId('carnum'),carnum);
				}
				//alert(JSON.stringify(ret));
			});
		}
		function selCartype(obj) {
			document.activeElement.blur();
			cartype = $api.attr(obj,'data-cartype');
			var liList = document.getElementById("cartypelist").children;
			for (var i = 0; i < liList.length; i++) {
				$api.removeCls(liList[i], 'on')
			}
			$api.addCls(obj,'on');
			$api.toggleCls($api.byId('hegepicdiv'),'display-none');
			$api.toggleCls($api.byId('xingshizhengdiv'),'display-none');
		}
		function selPictype(obj,typeid) {
			document.activeElement.blur();
			var liList = document.getElementById("havepictypelist").children;
			for (var i = 0; i < liList.length; i++) {
				$api.removeCls(liList[i], 'on')
			}
			$api.addCls(obj,'on');
			if(typeid == 1)
			{
				pictype = 1;
				$api.css($api.byId('picarea'),'display:block');
			}
			else
			{
				pictype = 0;
				$api.css($api.byId('picarea'),'display:none');
			}
		}
		function delimg(obj,id) {
			//清楚已选图片
			event.stopPropagation();
			$api.removeCls(obj.parentNode,'on');
			$api.val($api.byId('cardIDthumb_'+id),'');
			$api.byId('cardIDthumb'+id).src = '../../image/kong.png';
		}
		function selpic(id) {
			
			api.actionSheet({
				cancelTitle: '取消',
				buttons: ['拍照', '从手机相册选择'],
				style: {
					layerColor:'rgba(0,0,0,0.3)',         //遮蔽层颜色，仅支持 rgba颜色，默认值：rgba（0, 0, 0, 0.4）
					itemNormalColor:'#fff',    //选项按钮正常状态背景颜色，支持#000、#000000、rgb、rgba，默认值：#F1F1F1
					itemPressColor:'#f5f5f5',     //选项按钮按下时背景颜色，支持#000、#000000、rgb、rgba，默认值：#E6E6E6
					fontNormalColor:'#333',    //选项按钮正常状态文字颜色，支持#000、#000000、rgb、rgba，默认值：#007AFF
					fontPressColor:'#000',     //选项按钮按下时文字颜色，支持#000、#000000、rgb、rgba，默认值：#0060F0
					titleFontColor:'#000'      //标题文字颜色，支持#000、#000000、rgb、rgba，默认值：#8F8F8F
				}
			}, function(ret, err) {
				if(ret.buttonIndex==1 || ret.buttonIndex==2)
				{
					getPicture(ret.buttonIndex,id);
				}
			});
		}
		function openAlbum() {
			getPicture(2,curImgId);
		}
		function openCamera() {
			getPicture(1,curImgId);
		}
		function getPicture(index,id){
			curImgId = id;
			var perdesc = '相册/本地存储';
			var sourceType = 'library';
			var callbakstr = openAlbum;
            if(index==1){
				var pername = new Array('storage','camera');
				sourceType = 'camera';
				perdesc = '相册/拍照';
				callbakstr = openCamera;
				
				if (api.systemType == "android") {
					if(!confirmPerarr(pername,perdesc,callbakstr)){
						return;
					}
				}
			}
			else
			{
				var pername = 'photos';
				if (api.systemType == "android") {
					if(pername == 'photos')
					{
						pername = 'storage';
					}
					if(!confirmPer(pername,perdesc,callbakstr)){
						return;
					}
				}
			}
			api.getPicture({
				sourceType: sourceType,
				encodingType: 'png',
				mediaValue: 'pic',
				targetWidth: 600,
			}, function(ret, err) {
			// 获取图片数据并处理
				if (ret) {
					var imgSrc = ret.data;
					if (imgSrc != "") {
						uploadImage(imgSrc,id);
					}
				}
			});
		}
		function uploadImage(item,id)
		{
			var imageCachePath = api.cacheDir;
			var picname = randomString(32);
			imgFilter(item,id);
		}
		function randomString(len) {
		　　len = len || 32;
		　　var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
		　　var maxPos = $chars.length;
		　　var pwd = '';
		　　for (i = 0; i < len; i++) {
		　　　　pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
		　　}
		　　return pwd;
		}
		function imgFilter(item,id) {
			console.log(item+'压缩前路径');
			//压缩图片
			var picname = randomString(32);
			var imageCachePath = api.cacheDir;
			var imageFilter = api.require('imageFilter');
			imageFilter.compress({
				img: item,
				quality : 1,
				scale : 1,
				save : {
					album : false,
					imgPath : imageCachePath,
					imgName : picname + '.jpg'
				}
			},function( ret, err ){        
				if( ret.status ){
					//$api.attr($api.byId('cardIDthumb'+id),'src',imageCachePath + '/' + picname + '.jpg');
					$api.byId('cardIDthumb'+id).src = imageCachePath + '/' + picname + '.jpg';
					if(!$api.hasCls($api.byId('cardIDthumb'+id).parentNode, 'on'))
					{
						$api.addCls($api.byId('cardIDthumb'+id).parentNode, 'on');
					}
					var picurl = $api.attr($api.byId('cardIDthumb'+id),'src');
					var trans = api.require('trans');
					trans.decodeImgToBase64({
						imgPath: picurl
					}, function(ret, err) {
						if (ret.status) {
							//转换成base64后上传
							var paramsObj = {
								base64str: 'data:image/jpeg;base64,'+ret.base64Str
							}
							uponeimg(paramsObj,'cardIDthumb_'+id);
						}
					});

				}else{
					alert( JSON.stringify( err ) );
				}
			});
		}
		function uponeimg(pObj,domid) {
			//上传单张图片
			api.showProgress({
				title: '请稍后...',
				text: '',
				modal: true
			});
			api.ajax({
				url: ApiUrl + '/v1/upimgs',
				method: 'post',
				cache: false,
				timeout: 10,
				headers: {
				},
				data: {
					values: pObj
				}
			}, function(ret, err) {
				api.hideProgress();
				if (ret) {
					$api.val($api.byId(domid),ret.picurl);
				}
			});
		}
		function checkCarnum() {
			//判断车牌号是否已参保
			var carnum = $api.val($api.byId('carnum')).trim();
			var paramsObj = {
				carnum: carnum
			};
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret && ret.value)
				{
					var userinfo = JSON.parse(ret.value);
					api.ajax({
						url: ApiUrl + '/v1/insureextra',
						method: 'post',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						},
						data: {
							values: paramsObj
						}
					}, function(ret, err) {
						if (ret) {
							//var insureid = ret.insureid;
							if(ret.isxubao) {
								api.alert({
									title: '温馨提示',
									msg: '监测到本车还在保质期内，本次办理为续保！',
									buttons: ["我知道了"]
								}, function(ret, err) {
									if(ret.buttonIndex == 1)
									{
									}
								});
							}
							
						}
					});
				}
			});
		}
		
		function openAlert()
		{
			var icon = 'sucess.png';
			var title = '货源发布成功';
			var msg = '请等待车主接单';
			var winname = 'root';
			var btntxt = '返回';
			var param = {
				icon: icon,
				title: title,
				msg: msg,
				btntxt: btntxt,
				winname: winname,
			};
			openNavWin('#ddd','noheadmsg_win','../public/noheadmsg_frm.html','发布货源',false,true,false,[],param);
		}
		
		//渲染数据
		function UpdateList(domId,templateId,jsondata,isAppend) {
			//console.log(JSON.stringify(jsondata));
			var act_content = $api.byId(domId);
			var tempFn = doT.template($api.byId(templateId).innerHTML);
			var resultText = tempFn(jsondata);
			//alert(isAppend);
			console.log(resultText);
			if(isAppend)
			{
				$api.append(act_content, resultText);
			}
			else
			{
				$api.html(act_content, resultText);
			}
			api.parseTapmode();
		}
		function IdentityCodeValid(code) { 
			var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
            var tip = "";
            var pass= true;

            if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
                tip = "身份证号格式错误";
                pass = false;
            }

			else if(!city[code.substr(0,2)]){
                tip = "地址编码错误";
                pass = false;
            }
            else{
                //18位身份证需要验证最后一位校验位
                if(code.length == 18){
                    code = code.split('');
                    //∑(ai×Wi)(mod 11)
                    //加权因子
                    var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
                    //校验位
                    var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
                    var sum = 0;
                    var ai = 0;
                    var wi = 0;
                    for (var i = 0; i < 17; i++)
                    {
                        ai = code[i];
                        wi = factor[i];
                        sum += ai * wi;
                    }
                    var last = parity[sum % 11];
                    if(parity[sum % 11] != code[17]){
                        tip = "校验位错误";
                        pass =false;
                    }
                }
            }
            //if(!pass) alert(tip);
            return pass;
        }
	</script>
</html>